home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DNet / DGopher.h < prev    next >
Text File  |  1996-07-05  |  10KB  |  344 lines

  1. // DGopher.h  
  2. // Internet Gopher client
  3. // by D. Gilbert, Mar 1992
  4. // DClap version Jan 94
  5.  
  6. #ifndef __DGOPHER__
  7. #define __DGOPHER__
  8.         
  9.         
  10. #include <DObject.h>
  11. #include <DTCP.h>
  12. #include <DTask.h>
  13. #include <DTaskMaster.h>
  14. #include <Dvibrant.h>
  15.  
  16.  
  17. extern  const    long         kReadMaxbuf;
  18. extern  const    short     kGopherPort;          // default/prime port #
  19.  
  20. class    DList;
  21. class    DGopherList;
  22. class DFile; 
  23. class DIconList;
  24. class DView; 
  25. class    DGoMenuBlock;
  26. class DGopherAbstract;
  27.  
  28.  
  29. class DGopherTalk : public DTCP {
  30. public:
  31.     long   fLinesRead;
  32.     DGopherTalk();
  33.     virtual void OpenQuery( char* host, short port, char* path, char* query, 
  34.                                                     char* viewchoice, char* plus, DFile* plusFile);
  35.     virtual Boolean ReadALine( char* appendToHandle, char*& result);
  36. };
  37.  
  38.  
  39.  
  40. struct DocLink {
  41.     enum DocLinkType { kNoLink, kString, kLine, kRect, kLineRect };
  42.     DocLinkType     fType;
  43.     short                    fParag, fChar;
  44.   union {
  45.         struct {
  46.             char*        fString;        
  47.             short        fSkip;
  48.             } string;
  49.         struct {
  50.             short fEndParag, fEndChar;
  51.             } line;
  52.         struct {
  53.             Nlm_RecT    fRect;
  54.             } rect;
  55.         };
  56.  
  57.     DocLink();
  58.     ~DocLink();
  59.     Boolean HasLink() { return fType != kNoLink; }
  60.     short Kind() { return fType; }
  61.     void Clear();
  62.     void DupData();
  63.     char *GetString( short& skipval);
  64.     void SetString( const char* thestr, short skipvalue= 0);
  65.     void SetSkip( short skipvalue);
  66.     void GetRect( Nlm_RecT& therect)    { therect= rect.fRect; }
  67.     void SetRect( Nlm_RecT therect);
  68.     void GetLine( short& atparag, short& atchar, short& endparag, short& endchar );
  69.     void SetLine( short atparag, short atchar, short endparag, short endchar );
  70.     void GetLineRect( Nlm_RecT& therect, short& atparag, short& atchar );
  71.     void SetLineRect( Nlm_RecT therect, short atparag, short atchar);
  72. };
  73.  
  74.  
  75.  
  76. class DGopher : public DTaskMaster {
  77. public:
  78.  
  79.     enum  TCPprotocols {
  80.         kUnknownProt = 0,
  81.         kUnsupportedProt,
  82.         kSMTPprot,
  83.         kGopherprot,
  84.         kHTTPprot,
  85.         kFileprot,  
  86.         kFTPprot,
  87.         kTelnetprot,
  88.         kTN3270prot,
  89.         kWhoisprot,
  90.         kFingerprot,
  91.         kPOPprot,
  92.         kNNTPprot,
  93.         kWAISprot
  94.         };
  95.  
  96.     enum    tasks { 
  97.         kGopherTask= 2200,
  98.                 // obsolete??
  99.         cNoCommand = 0,
  100.         cNewGopherFolder    = 2211,   // data is in gGopherData 
  101.         cNewGopherText        = 2212,        // " 
  102.         cNewGopherAsk            = 2213,        // data is in gCurrentGopher
  103.         cNewGopherFile        = 2214,        // " 
  104.         cNewGopherImage        = 2215,        // " 
  105.         cOpenGopherFolder    = 2221,      // data is in gGopherFile 
  106.         cOpenGopherText        = 2222,        // " 
  107.         cOpenGopherAsk        = 2223,        // data is in gCurrentGopher
  108.         cOpenGopherFile        = 2224,        // " 
  109.         cOpenGopherImage  = 2225,        // " 
  110.         cGopherNetDoc         = 2230,        // new dec'94
  111.         cGopherGetInfo         = 2242
  112.         };
  113.         
  114.     enum viewIDs {
  115.         kServerMapID = 1001,
  116.         kGopherMapID = 1002,
  117.         kGopherPlusMapID = 1003 
  118.         };
  119.     
  120.     enum    newResult {
  121.         kNewGopherOkay = 0,
  122.         kNewGopherNone = 1,
  123.         kNewGopherEnd  = -1,
  124.         kGetItemInfo = -2 
  125.         };
  126.         
  127.     enum    threadState {
  128.         kThreadNotStarted = 0,
  129.         kThreadDataOld,
  130.         kThreadDataNew,
  131.         kThreadDone,
  132.         kThreadStarted,
  133.         kThreadDoneReading,
  134.         kThreadReadingToDisk
  135.         };
  136.     
  137.         // basic gopher info, +INFO
  138.     char            fType;                 // The type of object (A_FILE, A_INDEX, etc) 
  139.     long            fItitle;            // index into fLink to null-terminated string for Title
  140.     long            fIdate;                // "  [Date,Size] in title 
  141.     long            fIsize;                // "  [Date,Size] in title
  142.     long            fIpath;                // "  path
  143.     long            fIhost;                // "  host
  144.     long            fIport;                // "  port
  145.     long            fIplus;                // "  plus info
  146.     short            fPort;                 // Port number on host   
  147.     char*            fLink;                // title/0path/0host/0port/0plus/0???/0etc...
  148.     long            fLinkLen;            // keep true length of fLink 
  149.     
  150.         // gopher+ info
  151.     char*            fDate ;                 // Date of object on host 
  152.     long            fDateLong;
  153.     char*            fDataSize;        // Size of object on host 
  154.     long            fSizeLong;
  155.     
  156.     char*            fAdminEmail;        // +ADMIN
  157.     DList*         fViews;        // +VIEWS, list of CGopherItemView 
  158.     DList*         fAskers;    // +ASK, list of CGopherItemAsk
  159.     short            fIsPlus;                // is a gopher+ link: yes, no, don't know
  160.     Boolean     fShortFolder;        // for minimum data, false is default    
  161.     Boolean        fHasAsk;                // gopher+, any item can also have ASK block
  162.     Boolean        fHaveReply;            // gopher+, if ASK dialog (fInfo) ready to reply
  163.     DFile*        fReplyFile;            // ASK reply file, if any
  164.     char*            fReplyData;            // ASK reply data other than file
  165.     DGoMenuBlock* fGoMenuBlock;    // +MENU data
  166.     DGopherAbstract* fAbstract;    // +ABSTRACT        
  167.     
  168.         // multi-protocol support
  169.     short            fProtocol;            // kGopher, kFTP, kHTTP, kSMTP, kETC
  170.     char*            fURL;                        // from +URL or otherways
  171.     Boolean        fIsLocal;                // for type file:///
  172.     Boolean        fIsMap;                  // html, go+ item that sends x,y or rect as query
  173.  
  174.         // internal data
  175.     char*            fInfo;                    // data read from service 
  176.     long            fInfoSize;            // can't use strlen for binary data @!
  177.     //InfoProc    fInfoHandler;     // app proc that handles incoming data during reads
  178.     DTask*        fInfoHandler;
  179.     
  180.     char            *fQuery;                // alternate query data ptr, temp
  181.     char            *fQueryPlus;        // append to query for +, local temp
  182.     char            *fQueryGiven;        // default value given in +QUERYSTRING
  183.     short            fTransferType;     //text/lines or binary or none ?
  184.     Boolean        fDeleted;
  185.     long            fMacType;
  186.     long            fMacSire;
  187.     Boolean        fSaveToDisk;
  188.     Boolean        fLaunch;
  189.     short            fCommand;
  190.     short            fViewchoice;
  191.     DGopherList    *fOwnerList;
  192.     DView         *fStatusLine;
  193.     DGopherTalk    *fTalker;
  194.     long            fBytesExpected;
  195.     long            fBytesReceived;
  196.     long            fConnectTime;
  197.     short            fThreadState;  
  198.     char*            fAppFile;                
  199.     short            fInUseCount;
  200.     DocLink*    fDocLink;
  201.  
  202.  
  203.     DGopher();
  204.     DGopher( char ctype, const char* link);
  205.     DGopher( DGopher* aGopher);
  206.     virtual ~DGopher();
  207.     virtual    Boolean suicide(void);   
  208.     virtual    Boolean suicide(short ownercount);
  209.     
  210.     static short StandardPort( short protocol);
  211.     static const char* GetTypeName( short listitem);
  212.     static char  GetTypeVal( short listitem);
  213.     static short GetTypeItem( char theType);
  214.     static Boolean  GetTypeSupport( short listitem);
  215.     static const char* GetProtoName( short listitem);
  216.     static char  GetProtoVal( short listitem);
  217.     static short GetProtoItem( char theProto);
  218.     static Boolean  GetProtoSupport( short listitem);
  219.  
  220.     virtual    void Initialize();
  221.     virtual void CopyGopher( DGopher* aGopher); 
  222.     virtual DObject* Clone();    // override
  223.     virtual void SetLink( char ctype, const char* link);
  224.     virtual void DeleteLink(Boolean onlyInfoline = false);
  225.     virtual void DeleteInfo();
  226.     
  227.     virtual void SetPlusInfo( short isPlus, Boolean hasAsk, char* plus);
  228.     virtual void DeleteViews();
  229.     virtual void DeleteAskers();
  230.     DList* CloneViews();
  231.     DList* CloneAskers();
  232.  
  233.     virtual const char* ShortName();  
  234.     virtual const char* GetName();
  235.     virtual const char* GetDate();
  236.     virtual const char* GetDataSize();
  237.     virtual const char* GetPath();
  238.     virtual const char* GetHost();
  239.     virtual const char* GetPort();
  240.     virtual const char* GetPlus();
  241.     virtual const char* GetProtocol();
  242.     virtual const char* GetURL();
  243.     virtual const char* GetKindName();
  244.  
  245.     virtual void StoreName(char* aStr);
  246.     virtual void StorePath(char* aStr);
  247.     virtual void StoreHost(char* aStr);
  248.     virtual void StorePort(char* aStr);
  249.     virtual void StorePlus(char *plus);
  250.     virtual void StorePlus(Boolean isplus);
  251.     virtual void StoreProtocol( short protocol);
  252.     virtual void StoreURL(char *plus);
  253.  
  254.     virtual void SetOwner( DGopherList* OwnerList);  
  255.     virtual Boolean Edit(long dialogID);
  256.     virtual Boolean Equals(DGopher* other);
  257.     virtual Boolean operator ==(DGopher* other);
  258.  
  259.     virtual void ToText(CharPtr& h, short indent = 0);
  260.     virtual void ToServerText(CharPtr& h, short itemNum);
  261.     virtual void ToPrettyText(CharPtr& h, short itemNum,
  262.                 Boolean showDate, Boolean showSize, Boolean showKind, Boolean showPath, 
  263.                 Boolean showHost, Boolean showPort, Boolean showAdmin);
  264.     
  265.     virtual void OpenQuery();
  266.     virtual void CloseQuery();
  267.     virtual void LocalQuery( char* viewchoice);
  268.     virtual void FinishRead();
  269.     virtual Boolean EndOfMessage();
  270.  
  271.     virtual void ReadALine(); 
  272.     virtual void ReadAChunk( long maxchunk);
  273.  
  274.     virtual void InfoTask();
  275.     virtual void ReadTask();
  276.     virtual Boolean IsMyTask(DTask* theTask); // override 
  277.     virtual void ProcessTask(DTask* theTask);  // override
  278.  
  279.     virtual void SetInfoHandler(DTask* handlerTask) { fInfoHandler= handlerTask; }
  280.     virtual void ShowMessage(const char* msg);
  281.     virtual void ShowProgress();
  282.     
  283.     virtual short CommandResult();
  284.     virtual short ItemForm(short viewchoice = 0);
  285.     virtual    void  SetAskReply( char* data, DFile* replyFile);
  286.     virtual    void  ClearAskReply();
  287.     virtual    void  SwapPathType(char oldtype, char newtype);
  288.     virtual short ThreadProgress(short update = 0);
  289.     virtual const char* GetViewChoiceKind();
  290.     virtual void  AddView( const char* viewkind);
  291.     virtual void  CheckViewMappers();
  292.     
  293.     virtual Boolean HasDocLink();
  294.  
  295.     virtual void DrawIcon( Nlm_RecT& area, short size);  
  296.     virtual void DrawIconSub( Nlm_RecT& area);  
  297.     virtual void DrawTitle( Nlm_RecT& area);  
  298.     virtual void DrawKind( Nlm_RecT& area);  
  299.     virtual void DrawDate( Nlm_RecT& area);  
  300.     virtual void DrawSize( Nlm_RecT& area);  
  301.     virtual void DrawPath( Nlm_RecT& area);  
  302.     virtual void DrawHost( Nlm_RecT& area);  
  303.     virtual void DrawPort( Nlm_RecT& area);  
  304.     virtual void DrawPlus( Nlm_RecT& area);  
  305.     virtual void DrawAdmin( Nlm_RecT& area);  
  306.     virtual void DrawAbstract( Nlm_RecT& area);  
  307.     virtual void DrawURL( Nlm_RecT& area);  
  308.  
  309.     virtual short WidthIcon(short size);
  310.     virtual short WidthTitle();  
  311.     virtual short WidthKind();  
  312.     virtual short WidthDate();  
  313.     virtual short WidthSize();  
  314.     virtual short WidthPath();  
  315.     virtual short WidthHost();  
  316.     virtual short WidthPort();  
  317.     virtual short WidthPlus();  
  318.     virtual short WidthAdmin();  
  319.     virtual short HeightAbstract();  
  320.     
  321. };
  322.  
  323.  
  324.  
  325.         // these should be private, but need in UGopherClass.cp & UGopher.cp
  326. //extern void*        gIcons[];
  327. //extern void*        gGopherIcon; //pointer to gIcons[i], may be CIconHandle or Handle 
  328. //extern Boolean    gIconIsCicon;
  329. extern DIconList*    gGopherIcons;
  330. extern short        gGopherIconID;
  331. extern short        gIconSize;
  332.  
  333. extern Boolean    gUseDigFolder;
  334. extern short        gDigVol;
  335. extern long            gDigDirID;
  336. ///
  337. extern Boolean    gListUnknowns;
  338. extern Boolean    gDoSuffix2MacMap;
  339. extern Boolean    gShortFolder;
  340. extern char*        gLocalGopherRoot;
  341. extern char*        gAskWaisPath;
  342.  
  343. #endif
  344.